package com.xcdh.commons.utils;

import org.apache.commons.lang3.text.WordUtils;

import java.util.Locale;

public class StringUtil {

    /**
     * 转换为驼峰命名
     * @param columnName
     * @return
     */
    public static String toHump(String columnName){
        if(columnName != null){
            String[] names = columnName.split("_");
            if(names.length == 1){
                return columnName ;
            }else{
                StringBuffer stringBuffer = new StringBuffer(names[0]) ;
                for (int i = 1; i < names.length; i++) {
                    stringBuffer.append( WordUtils.capitalizeFully(names[i], new char[]{'_'}).replace("_", "")) ;
                }
                return stringBuffer.toString() ;
            }

        }
        return null ;
    }
    /**
     * 转换为驼峰命名
     * @param columnName
     * @return
     */
    public static String toHumpAll(String columnName){
        if(columnName != null){
            String[] names = columnName.split("_");
            StringBuffer stringBuffer = new StringBuffer() ;
            for (int i = 0; i < names.length; i++) {
                stringBuffer.append( WordUtils.capitalizeFully(names[i], new char[]{'_'}).replace("_", "")) ;
            }
            return stringBuffer.toString() ;

        }
        return null ;
    }

    public static String firstLower(String input){
        if (input == null || input.isEmpty()) {
            return input; // 如果输入为空或为空字符串，返回原字符串
        }

        char[] charArray = input.toCharArray(); // 将字符串转换为字符数组
        charArray[0] = Character.toLowerCase(charArray[0]); // 将首字符转为小写
        return new String(charArray); // 将字符数组转换回字符串
    }
}
